package game.metalmax.ui.main
{
	import fl.controls.Button;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import game.metalmax.controller.Notifications;
	import game.metalmax.ui.common.Button001;
	
	import showtime.framework.manager.AssetManager;
	import showtime.framework.manager.WindowManager;
	import showtime.framework.mvc.patterns.facade.Facade;
	import showtime.framework.ui.Window;

	/**
	 * MainWindow.as
	 * Yin Hao
	 * @version 1.0.0
	 * 
	 * Description.
	 * 
	 * Copyright (c) 2012 Yin Hao
	 * 
	 * Permission is hereby granted, free of charge, to any person obtaining a copy
	 * of this software and associated documentation files (the "Software"), to deal
	 * in the Software without restriction, including without limitation the rights
	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	 * copies of the Software, and to permit persons to whom the Software is
	 * furnished to do so, subject to the following conditions:
	 * 
	 * The above copyright notice and this permission notice shall be included in
	 * all copies or substantial portions of the Software.
	 * 
	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	 * THE SOFTWARE.
	 */
	public class MainWindow extends Window
	{
		private var exitBtn:Button = null;
		private var transferBtn:Button = null;
		
		public function MainWindow()
		{
		}
		
		override protected function initialize():void
		{
			super.initialize();
			size(330, 170);
			
			addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		override protected function createChildren():void
		{
			var window:Sprite = new (AssetManager.getInstance().getClass("MAIN_SPRITE_MAIN_WINDOW"));
			window.width = 330;
			window.height = 170;
			addChild(window);
			
			exitBtn = new Button001();
			exitBtn.label = "关闭";
			exitBtn.move(20, 135);
			exitBtn.width = 84;
			exitBtn.height = 25;
			addChild(exitBtn);
			
			transferBtn = new Button001();
			transferBtn.label = "换乘";
			transferBtn.move(210, 20);
			transferBtn.width = 84;
			transferBtn.height = 25;
			addChild(transferBtn);
		}
		
		private function clickHandler(evt:MouseEvent):void
		{
			if (evt.target == exitBtn)
			{
				WindowManager.removePopUp(MainWindow);
				Facade.getInstance().sendNotification(Notifications.ACTIVE_ZONE);
			}
			else if (evt.target == transferBtn)
			{
				WindowManager.centerPopUp(WindowManager.createPopUp(TransferWindow, parent, true));
			}
		}
	}
}